﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Vehicle.Web.Pages.Task
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Main.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-09-02   Created by 杨光远 V1.00.0000
    /// 功能说明：查询承运任务页面类
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Main : Component.PageBase
    {
        #region---基本实例化---
        Vehicle.BLL.Task b_Task = new Vehicle.BLL.Task();
        Vehicle.BLL.Vehicles b_Vechicles = new Vehicle.BLL.Vehicles();
        Vehicle.BLL.Motorcade b_Motorcade = new Vehicle.BLL.Motorcade();//定义逻辑层变量
        Vehicle.Model.ComponentsInfo m_ComponentsInfo = new Vehicle.Model.ComponentsInfo();
        public string onshow;//定义没有数据时页面的显示内容
        #endregion

        #region---基本操作---
        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MotorcadeDataBind();//绑定车队
                VehiclesDataBind();//绑定车辆
                TaskDataBind();//绑定
            }

        }

        /// <summary>
        /// 初始绑定车队
        /// </summary>
        public void MotorcadeDataBind()
        {
            b_Motorcade.DropDownListBind(drop_M_ID);//绑定车队
            drop_M_ID.Items.FindByValue("0").Text = "全部";
            drop_M_ID.SelectedValue = "0";

        }
        /// <summary>
        /// 根据车队下拉菜单绑定下属车辆
        /// </summary>
        public void VehiclesDataBind()
        {
            b_Vechicles.DropDownListBind(drop_V_ID, new Vehicle.Model.ComponentsInfo("Vehicles", "M_ID", drop_M_ID.SelectedValue, "0", "0", "V_IsDelete", "1", "V_ID"));
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void TaskDataBind()
        {

            if (rbt_C_Card.Checked)//按编号承运单查询
            {
                ReptShow.DataSource = b_Task.GetModel(new Vehicle.Model.ComponentsInfo("Task","C_Card",txt_C_Card.Text.Trim(),"1","1","T_IsDelete","1","T_ID")).DefaultView;
                ReptShow.DataBind();
            }
            else if (rbt_C_Num.Checked)//按任务编号
            {
                ReptShow.DataSource = b_Task.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_Num", txt_C_Num.Text.Trim(), "1", "1", "T_IsDelete", "1", "T_ID")).DefaultView;
                ReptShow.DataBind();
            }
            else if (rbt_C_Select.Checked)//按条件查询
            {

                m_ComponentsInfo.startIndex = 0;//当前页的起始索引
                m_ComponentsInfo.endIndex = b_Task.GetAllSearchCount(new Model.ComponentsInfo("Task", drop_M_ID.SelectedValue == "0" ? "1" : "M_ID", drop_M_ID.SelectedValue == "0" ? "1" : drop_M_ID.SelectedValue, drop_V_ID.SelectedValue == "0" ? "1" : "V_ID", drop_V_ID.SelectedValue == "0" ? "1" : drop_V_ID.SelectedValue, "T_IsDelete", "1", "T_Time", Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_Start.DateString), Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_End.DateString), "T_ID"));//当前页的结束索引
                m_ComponentsInfo.tableName = "Task";//表名
                m_ComponentsInfo.condition = drop_M_ID.SelectedValue == "0" ? "1" : "M_ID";//条件一
                m_ComponentsInfo.result = drop_M_ID.SelectedValue == "0" ? "1" : drop_M_ID.SelectedValue;//匹配结果一
                m_ComponentsInfo.Tcondition = drop_V_ID.SelectedValue == "0" ? "1" : "V_ID";//条件二
                m_ComponentsInfo.Tresult = drop_V_ID.SelectedValue == "0" ? "1" : drop_V_ID.SelectedValue;//匹配结果二
                m_ComponentsInfo.Scondition = "T_IsDelete";//条件三
                m_ComponentsInfo.Sresult = "1";//匹配结果三
                m_ComponentsInfo.Count = "T_Time";//时间
                m_ComponentsInfo.order = "T_ID";//排序
                if (Gmdp_Start.Date != null)//判断起始时间是否为空
                {
                    m_ComponentsInfo.StartTime = Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_Start.DateString);
                }
                if (Gmdp_End.Date != null)//判断结束时间是否为空
                {   
                    m_ComponentsInfo.EndTime = Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_End.DateString);
                }
                ReptShow.DataSource = b_Task.GetAllSearch(m_ComponentsInfo).DefaultView;
                ReptShow.DataBind();//绑定Repeater控件
            }
            if (ReptShow.Items.Count == 0)//判断没有数据时页面的显示内容
            {
                onshow = "当前页面无数据";
            }
            else
            {
                onshow = "";
            }
        }
        /// <summary>
        /// 根据时间查询数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Select_Click(object sender, EventArgs e)
        {
            TaskDataBind();
        }
        /// <summary>
        /// Rept绑定数据事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {

                Label lab_T_Type = (Label)e.Item.FindControl("lab_T_Type");//更改接收情况
                switch (lab_T_Type.Text)
                {
                    case "0": lab_T_Type.Text = "已取消"; break;
                    case "1": lab_T_Type.Text = "执行中"; break;
                    case "2": lab_T_Type.Text = "已完成"; break;
                }
                Label lab_M_ID = (Label)e.Item.FindControl("lab_M_ID");
                Label lab_V_ID = (Label)e.Item.FindControl("lab_V_ID");
                Label lab_P_ID = (Label)e.Item.FindControl("lab_P_ID");
                try
                {
                    lab_M_ID.Text = b_Task.GetModel(new Vehicle.Model.ComponentsInfo("Motorcade", "M_ID", lab_M_ID.Text, "M_ID")).Rows[0]["M_Name"].ToString();//绑定车队名称
                }
                catch
                {
                    lab_M_ID.Text = "无";
                }
                try
                {
                    lab_V_ID.Text = b_Task.GetModel(new Vehicle.Model.ComponentsInfo("Vehicles", "V_ID", lab_V_ID.Text, "V_ID")).Rows[0]["V_LicenseNum"].ToString();//绑定车牌号码
                }
                catch
                {
                    lab_V_ID.Text = "无";
                }
                try
                { 
                    lab_P_ID.Text = b_Task.GetModel(new Vehicle.Model.ComponentsInfo("Pilot", "P_ID", lab_P_ID.Text, "P_ID")).Rows[0]["P_Name"].ToString();//绑定驾驶员姓名
                }
                catch
                {
                    lab_P_ID.Text = "无";
                }

            }

        }
        /// <summary>
        /// 根据车队选择数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void drop_M_ID_SelectedIndexChanged(object sender, EventArgs e)
        {
            VehiclesDataBind();
        }
        #endregion
    }
}
